<?php 
session_start();
include "connectdb.php";

$id = $_GET['vdo_id'];

//echo "id = $vdo_id<br>\n";
//echo "vote = $vote<br>\n";
//echo "---------------------------<br>\n";

$SQL_SELECT_MAXVC = "SELECT vdo_votecount FROM ag_vdodetail where vdo_id = $vdo_id;";
$resultmax1 = mysql_db_query($dbname,$SQL_SELECT_MAXVC);
$resultmax2 = mysql_fetch_array($resultmax1);
$r1 = $resultmax2["vdo_votecount"];
//echo "orig vote count = $r1<br>\n";
$resultmaxvc = $r1+1;
//echo "new vote count = $resultmaxvc<br>\n";
$SQL_UPDATE_VOTEC = "UPDATE ag_vdodetail SET vdo_votecount = $resultmaxvc where vdo_id = $vdo_id;";

//echo "---------------------------<br>\n";

$SQL_SELECT_MAXVS = "SELECT vdo_votesum FROM ag_vdodetail where vdo_id = $vdo_id;";
$resultmax3 = mysql_db_query($dbname,$SQL_SELECT_MAXVS);
$resultmax4 = mysql_fetch_array($resultmax3);
$r2 = $resultmax4["vdo_votesum"];
//echo "orig vote sum = $r2<br>\n";
$resultmaxvs = $r2+$vote;
//echo "new vote sum = $resultmaxvs<br>\n";
$SQL_UPDATE_VOTES = "UPDATE ag_vdodetail SET vdo_votesum = $resultmaxvs where vdo_id = $vdo_id;";
//echo "---------------------------<br>\n";
$resultC = mysql_db_query($dbname,$SQL_UPDATE_VOTEC);

$resultS = mysql_db_query($dbname,$SQL_UPDATE_VOTES);

$vote=0;

//============== เช็คโหวตซ้ำ ==================//
$svdoid = "ssvdovote".$_GET['vdo_id'];
$_SESSION[$svdoid] = 1;
//echo "<br>sess name = ".$svdoid;
//echo "<br>sess value = ".$_SESSION[$svdoid];
//==========================================//


?>
<script>
alert("โหวตเรียบร้อยแล้ว");
history.back();
<?php /*?>history.back();<?php */?>
</script>
<meta http-equiv='refresh' content='0;URL=vdo_player2.php?id=<?=$vdo_id?>&vote=0'>